package pkg;

import java.awt.*;
import java.util.*;

public class ComponentCollection {
	
	ArrayList<IGameComponent> components;
	public ComponentCollection()
	{
		components = new ArrayList<IGameComponent>();
	}
	
	public void initialize()
	{
		for(IGameComponent component : components)
			component.initialize(this);
	}
	
	public void addComponent(IGameComponent comp)
	{
		components.add(comp);
	}
	
	public void render(Graphics2D g)
	{
		for(IGameComponent component : components)
			component.render(g);
	}
	
	public void update(float dt)
	{
		for(IGameComponent component : components)
			component.update(dt);
	}
	
	public IGameComponent find(Class<?> componentClass)
	{
		for(IGameComponent component : components)
			if(component.getClass().equals(componentClass))
				return component;
		return null;
	}
	
	protected interface IGameComponent
	{
		public void initialize(ComponentCollection colection);
		public void update(float dt);
		public void render(Graphics2D g);
	}
}


